import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.Graphics;

public class Balón {

	double x, y, vx, vy, v, d;
	Image img;
	ImageObserver io;
	
	public Balón(Image img, double x, double y, double v, double d, ImageObserver io){
		this.x = x;
		this.y = y;
		this.v = v;
		this.d = d;
		this.img = img;
		this.io = io;
		vx = v * Math.cos(d);
		vy = -(v * Math.sin(d));
	}
	
	public void mover(int minX, int minY, int maxX, int maxY){
		x += vx;
		y += vy;
		
		if (x + img.getWidth(io) > maxX){
			x = maxX - img.getWidth(io);
			vx = -vx;
		}else if (x < 0){
			x = 0;
			vx = -vx;
		}
		
		if (y + img.getHeight(io) > maxY){
			y = maxY - img.getHeight(io);
			vy = -vy;
		}else if (y < 0){
			y = 0;
			vy = -vy;
		}
	}
	
	public void paint(Graphics g){
		g.drawImage(img, (int)Math.round(x), (int)Math.round(y), io);
	}

	public int getX(){
		return (int) Math.round(x);
	}
	
	public int getY(){
		return (int) Math.round(y);
	}
	
	public int getCX(){
		return (int)Math.round( x + img.getWidth(io) / 2);
	}
	
	public int getCY(){
		return (int)Math.round( y + img.getWidth(io) / 2);
	}
	public int getRadio(){
		return img.getWidth (io) / 2;
	}
	public boolean moverXY (int x, int y, int w, int h){
		this.x = x; 
		this.y = y;
		return (x < 0 || y < 0 || 
				x + img.getWidth(io) > w ||
				y + img.getWidth(io) > h);
	}
	
	public boolean colision (Balón balón){
		int dx = getCX() - balón.getCX();
		int dy = getCY() - balón.getCY();
		d= (int) Math.round(Math.sqrt(dx * dx + dy *  dy));
		return (d <= getRadio() + balón.getRadio());
		
		
	}
}